#coding:utf-8
"""
*   TG_Coder : Dzlua
*   Email    : 505544956@qq.com
*   Time     : 2017/09/08
"""

from database import DataBase
from bs4 import BeautifulSoup
import re
import codecs

import string, sys, os

import ftplib

from progressbar import *

class Upload(DataBase):
    def __init__(self, host, user, pwd, db):
        self._src_root = '/home/zhouhan/dzlua/tg-data-back/tg-data/src'
        self._dst_root = '/home/zhouhan/dzlua/tg-data-back/tg-data/tar'

        DataBase.__init__(self, host, user, pwd, db)
    def start(self, bid, eid):
        self.read(self.__on_read, [bid, eid])
    def __on_read(self, conn, args):
        bid = args[0]
        eid = args[1]

        count = self._getCount(conn)
        id = bid
        while id < count and id <= eid:
            print('------------------------------')
            print('[ToUdisk] id:%s/%d[%s,%s], num:%s' % (id, count, bid, eid, id-bid+1) )
            sql = "SELECT id,name,type,src,dst FROM toudisk WHERE id=%s;" % id
            result = self._select(conn, sql)
            for r in result:
                info = {
                    'id': r[0],
                    'name': r[1],
                    'type': r[2],
                    'src': r[3],
                    'dst': r[4],
                }
                '''
                try:
                    self._getPjo(info)
                except:
                    errmsg = '[ToUdisk] ERROR id:%s,name:%s' % (id, info['name'])
                    self.write(errmsg + '\n')
                    print(errmsg)
                '''
                self._getPjo(info)
                break
            id = id +1